import Category from '@/database/models/category'

const getCategories = async () => {
  const categories = await Category.findAll({
    where: {
      parentId: null,
    },
    attributes: { exclude: ['createdAt', 'updatedAt'] },
    include: {
      model: Category,
      as: 'children',
      attributes: { exclude: ['createdAt', 'updatedAt'] },
      include: [
        {
          model: Category,
          as: 'children',
          attributes: { exclude: ['createdAt', 'updatedAt'] },
        },
      ],
    },
  })
  return { categories }
}

export default {
  getCategories,
}
